<template>
	<view>
		<view class="goods-item">
			<!-- 左侧盒子 -->
			<view class="goods-item-left">
				<label class="radio" v-if="showRadio">
					<radio value="" :checked="goods.goods_state" color="#c00000" @click="radioChange" /><text></text>
				</label>
				<image :src="goods.goods_small_logo||defaultImg" class="goods-img"></image>
			</view>
			<!-- 右侧盒子 -->
			<view class="goods-item-right">
				<view class="goods-name">
					{{goods.goods_name}}
				</view>
				<view class="goods-info-box">
					<view class="goods-price">
						￥{{goods.goods_price | tofixed}}
					</view>
					<uni-number-box :min="1" :value="goods.goods_count" v-if="showNum" @change="changeNum">
					</uni-number-box>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "my-goods",
		props: {
			goods: {
				type: Object,
				default: {}
			},

			showRadio: {
				type: Boolean,
				default: false
			},
			showNum: {
				type: Boolean,
				default: false
			}
		},
		filters: {
			tofixed(num) {
				return Number(num).toFixed(2)
			}
		},
		data() {
			return {
				//默认图片
				defaultImg: 'https://ts1.cn.mm.bing.net/th/id/R-C.bdf8fdce8ee3751721a835ce16500f12?rik=UO4BcMRgXVWWzg&riu=http%3a%2f%2fimg.crcz.com%2fallimg%2f201910%2f25%2f1571988943120600.jpg&ehk=VRlfSW1equL8LRa5MkabpSZn37T551gGdrZzreRRaqw%3d&risl=&pid=ImgRaw&r=0&sres=1&sresct=1'
			};
		},
		methods: {
			radioChange() {
				this.$emit('changeChecked', {
					goods_id: this.goods.goods_id,
					goods_state: !this.goods.goods_state
				})
			},
			changeNum(val) {
				this.$emit('num-change', {
					goods_id: this.goods.goods_id,
					goods_count: val - 0
				})
			}
		}
	}
</script>

<style lang="scss">
	.goods-item {
		width: 750rpx;
		box-sizing: border-box;
		display: flex;
		padding: 10px 5px;
		border-bottom: 1px solid #efefef;

		.goods-item-left {
			margin-right: 5px;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.goods-img {
				width: 100px;
				height: 100px;
				display: block;
			}

		}

		.goods-item-right {
			display: flex;
			flex: 1;
			flex-direction: column;
			justify-content: space-between;

			.goods-name {
				font-size: 14px;
			}

			.goods-info-box {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.goods-price {
					font-size: 16px;
					color: #c00000;
				}
			}
		}
	}
</style>
